﻿using System;

namespace HslCommunication.BasicFramework
{
	/// <summary>
	/// 一个内存队列缓存的类，数据类型为Int32
	/// </summary>
	// Token: 0x02000191 RID: 401
	public sealed class SoftCacheArrayInt : SoftCacheArrayBase
	{
		/// <summary>
		/// 实例化一个数据对象
		/// </summary>
		/// <param name="capacity"></param>
		/// <param name="defaultValue"></param>
		// Token: 0x060020B4 RID: 8372 RVA: 0x0009F488 File Offset: 0x0009D688
		public SoftCacheArrayInt(int capacity, int defaultValue)
		{
			bool flag = capacity < 10;
			if (flag)
			{
				capacity = 10;
			}
			base.ArrayLength = capacity;
			this.DataArray = new int[capacity];
			this.DataBytes = new byte[capacity * 4];
			bool flag2 = defaultValue != 0;
			if (flag2)
			{
				for (int i = 0; i < capacity; i++)
				{
					this.DataArray[i] = defaultValue;
				}
			}
		}

		/// <summary>
		/// 用于从保存的数据对象初始化的
		/// </summary>
		/// <param name="dataSave"></param>
		/// <exception cref="T:System.NullReferenceException"></exception>
		// Token: 0x060020B5 RID: 8373 RVA: 0x0009F4F8 File Offset: 0x0009D6F8
		public override void LoadFromBytes(byte[] dataSave)
		{
			int num = dataSave.Length / 4;
			base.ArrayLength = num;
			this.DataArray = new int[num];
			this.DataBytes = new byte[num * 4];
			for (int i = 0; i < num; i++)
			{
				this.DataArray[i] = BitConverter.ToInt32(dataSave, i * 4);
			}
		}

		/// <summary>
		/// 线程安全的添加数据
		/// </summary>
		/// <param name="value">值</param>
		// Token: 0x060020B6 RID: 8374 RVA: 0x0009F554 File Offset: 0x0009D754
		public void AddValue(int value)
		{
			this.HybirdLock.Enter();
			for (int i = 0; i < base.ArrayLength - 1; i++)
			{
				this.DataArray[i] = this.DataArray[i + 1];
			}
			this.DataArray[base.ArrayLength - 1] = value;
			for (int j = 0; j < base.ArrayLength; j++)
			{
				BitConverter.GetBytes(this.DataArray[j]).CopyTo(this.DataBytes, 4 * j);
			}
			this.HybirdLock.Leave();
		}

		/// <summary>
		/// 安全的获取数组队列
		/// </summary>
		/// <returns></returns>
		// Token: 0x060020B7 RID: 8375 RVA: 0x0009F5E8 File Offset: 0x0009D7E8
		public int[] GetIntArray()
		{
			this.HybirdLock.Enter();
			int[] array = new int[base.ArrayLength];
			for (int i = 0; i < base.ArrayLength; i++)
			{
				array[i] = this.DataArray[i];
			}
			this.HybirdLock.Leave();
			return array;
		}

		/// <summary>
		/// 数据的本身面貌
		/// </summary>
		// Token: 0x040007BC RID: 1980
		private int[] DataArray = null;
	}
}
